package org.java.energyprofile;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;

public class JavaUtilBenchmark {
	
	private final int ITERATIONS = 1000;
	
	
	public void doBenchmark() throws InterruptedException {
		System.out.println("javaUtilsBenchmark begin.");
		
		
		/**
		 * Testando os contrutores. 
		 */
		
		for (int i = 0; i < ITERATIONS; i++) 
			new ArrayList<String>();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++) 
			new HashMap<String, String>();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++) 
			new HashSet<String>();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++) 
			new Hashtable<String, String>();
		Thread.sleep(3000);
						
		for (int i = 0; i < ITERATIONS; i++) 
			new Vector<String>();
		Thread.sleep(3000);
		
		/**
		 * Testando operações. 
		 */
		ArrayList<String> a = new ArrayList<String>();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			a.add("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			a.contains("A");		
		for (int i = 0; i < ITERATIONS; i++) 
			new Date();
		Thread.sleep(3000);
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			a.get(1);
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			a.indexOf("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			a.remove(0);
		Thread.sleep(3000);
		
		/************************************************************************************/
		
		HashMap<String, String> m = new HashMap<String, String>();
		Thread.sleep(3000);
				
		for (int i = 0; i < ITERATIONS; i++)
			m.put("" + 1 , "A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			m.get("1");		
		for (int i = 0; i < ITERATIONS; i++) 
			new Date();
		Thread.sleep(3000);
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			m.containsKey("123");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			m.containsValue("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			m.keySet();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			m.isEmpty();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			m.values();
		Thread.sleep(3000);
		
		/************************************************************************************/
		
		HashSet<String> s = new HashSet<String>();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			s.add("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			s.contains("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			s.remove(0);
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			s.toArray();
		Thread.sleep(3000);
				
		for (int i = 0; i < ITERATIONS; i++)
			s.size();
		Thread.sleep(3000);
		
		/************************************************************************************/
		
		Hashtable<String, String> t = new Hashtable<String, String>();
		Thread.sleep(3000);
				
		for (int i = 0; i < ITERATIONS; i++)
			t.put("" + 1 , "A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			t.get("1");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			t.containsKey("123");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			t.containsValue("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			t.keySet();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			t.isEmpty();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			t.values();
		Thread.sleep(3000);
		
		/************************************************************************************/
		
		Vector<String> v = new Vector<String>();
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			v.add("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			v.contains("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			v.get(1);
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			v.indexOf("A");
		Thread.sleep(3000);
		
		for (int i = 0; i < ITERATIONS; i++)
			v.remove(0);
		Thread.sleep(3000);
	}
}
